package site.xuxingcan;

import io.netty.util.internal.SystemPropertyUtil;
import site.xuxingcan.file.HttpStaticFileServer;
import site.xuxingcan.upload.HttpUploadServer;

import java.io.File;
import java.util.Timer;
import java.util.TimerTask;

public class Main {
    public static String BASE_PATH;
    public static String MYSQL_URI = "127.0.0.1:3306/user_info", MYSQL_USER = "root", MYSQL_PWD = "xxc65734101";
    public static String PWD = "xxc";

    public static void main(String[] args) {
        try {
            PWD = args[0];
        } catch (Exception e) {
            e.printStackTrace();
        }
        // write your code here
        String rootPath = SystemPropertyUtil.get("user.dir");
        File dir = new File(rootPath, "files");
        if (!dir.exists()) {
            dir.mkdir();
        }
        BASE_PATH = dir.getAbsolutePath();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    HttpStaticFileServer.main(null);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    HttpUploadServer.main(null);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                MysqlUtil.getInstance().heartBeat();
            }
        }, 60 * 60 * 1000, 60 * 60 * 1000);
    }
}